home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_08_07
/
8n07091a
< prev
next >
Wrap
Text File
|
1990-06-17
|
983b
|
57 lines
main()
{
int i = 0XFFFF;
double d = 123456789.123456789;
char c;
/* This is okay, cast does nothing */
(char) c = 'A';
printf("\n I is %x", i);
(char) i = 'A';
printf("\n I is %x", i);
*(&(char)i + 1) = 'B';
printf("\n I is %x", i);
/* Show it the "right" way */
i = 0XFFFF;
printf("\n I is %x", i);
*((char *) &i + 1) = 'B';
printf("\n I is %x", i);
/* Now try it with a double */
printf("\n d is %lf", d);
(int) d = 'C';
printf("\n d is %lf", d);
/* This causes a compiler error -- */
/* This was removed so that the listing could be
produced */
(double) i = 'A';
}
Results:
I is ffff
I is ff41
I is 4241
I is ffff
I is 42ff
d is 123456789.123457
d is 123456789.123048